<template>
	<view class="deta">
		<uv-navbar leftIcon="arrow-leftward" leftIconColor="#FFF" placeholder autoBack bgColor="#161714">
			<template v-slot:center>
				<view class="center_slot">{{data_info.product_name}}</view>
			</template>
			<!-- <template v-slot:right>
				<view class="right_slot">
					<image src="@/static/images/6.png"></image>
				</view>
			</template> -->
		</uv-navbar>
		<scroll-view scroll-y class="scroll_view">
			<view class="content">
				<image :src="data_info.cover" mode="widthFix" class="cover"></image>
				<view class="info_view">
					<view class="name">【{{data_info.name}}】</view>
					<view class="list">
						<view class="item">
							<view class="key">{{$t('home.发行总量')}}</view>
							<view class="value">{{data_info.issue_all}}份</view>
						</view>
						<view class="item cell">
							<view class="key">TOKEN</view>
							<view class="value">50xsdfdsfgrg1223550xsdfdsfgrg1223550xsdfdsfgrg12235</view>
						</view>
					</view>
				</view>
				<view class="charts" @click="charts_open">
					<view class="left">
						<image src="@/static/images/17.png"></image>
						<view class="text">{{$t('market.价格走势')}}</view>
					</view>
					<view class="right">
						<view class="text">{{$t('market.查看')}}</view>
						<image src="@/static/images/r1.png"></image>
					</view>
				</view>
				<view class="title">{{$t('market.介绍')}}</view>
				<view class="parse_view">
					<uv-parse :content="data_info.content"></uv-parse>
				</view>
			</view>
		</scroll-view>
		<view class="footer">
			<view class="left">
				<text class="unit">{{$t('market.一口价')}}$</text>
				<text class="value">{{order_info.price}}</text>
			</view>
			<view class="btn" @click="buy">{{$t('home.购买')}}</view>
		</view>
		<uv-popup ref="popup" round="10" bgColor="none" mode="bottom">
			<CodeInput :data="order_info" @close="popup.close" @submit="submit" />
		</uv-popup>

		<uv-popup ref="chartsRef" round="10" bgColor="none">
			<Charts :id="data_info.id" :data_info="order_info" @close="chartsRef.close" />
		</uv-popup>
	</view>
</template>

<script setup>
	import {
		orderInfo,
		orderSellBuy
	} from "@/request/api";
	import CodeInput from "@/components/market/CodeInput.vue"
	import Charts from "@/components/market/Charts.vue"
	import {
		onLoad
	} from "@dcloudio/uni-app";
	import {
		ref,
		shallowRef
	} from "vue";
	import useBase from "@/hooks/useBase.js";
	const {
		router
	} = useBase();
	const content = ref("111");

	const chartsRef = shallowRef();
	const charts_open = () => chartsRef.value.open();

	const popup = shallowRef();
	const buy = () => popup.value.open();

	const submit = async (value) => {
		let {
			id: order_id
		} = await orderSellBuy({
			id,
			pay_password: value
		});
		popup.value.close();
		uni.$uv.toast("操作成功");
		setTimeout(() => {
			router(`/pages/common/order_result?id=${order_id}`)
		}, 1000);
	};

	const data_info = ref({});
	const order_info = ref({});
	let id = "";
	onLoad(async (options) => {
		id = options.id;
		let {
			info,
			product
		} = await orderInfo({
			id: options.id
		});
		order_info.value = info;
		data_info.value = product;
	});
</script>

<style scoped lang="scss">
	$footerHeight: 108rpx;

	.deta {
		height: 100vh;
		overflow: hidden;

		.center_slot {
			color: #FFFFFF;
			font-size: 14px;
			font-weight: 800;
		}

		.right_slot {
			image {
				width: 24px;
				height: 24px;
			}
		}

		.scroll_view {
			height: calc(100vh - #{$navBarHeight} - #{$footerHeight});

			.content {
				padding: 20rpx;
				box-sizing: border-box;

				.cover {
					width: 100%;
				}

				.info_view {
					border-radius: 20rpx;
					margin: 20rpx 0;
					padding: 0 30rpx;
					box-sizing: border-box;
					background: #2E2E2E;

					.name {
						color: #FFFFFF;
						font-size: 32rpx;
						font-weight: 800;
						border-bottom: 1px solid #42433F;
						padding: 40rpx 0;
						box-sizing: border-box;
					}

					.list {
						padding-top: 20rpx;
						box-sizing: border-box;
						display: flex;
						flex-wrap: wrap;
						justify-content: space-between;

						.item {
							width: 50%;
							padding-bottom: 35rpx;
							box-sizing: border-box;

							&.cell {
								width: 100%;
							}

							.key {
								color: #808080;
								font-size: 26rpx;
								padding-bottom: 20rpx;
								box-sizing: border-box;
							}

							.value {
								color: #FFFFFF;
								font-size: 40rpx;
								font-family: DINPro;
								word-break: break-all;
							}
						}
					}
				}

				.charts {
					height: 100rpx;
					border-radius: 20rpx;
					padding: 0 24rpx 0 38rpx;
					box-sizing: border-box;
					background: #2E2E2E;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.left {
						display: flex;

						image {
							width: 38rpx;
							height: 38rpx;
						}

						.text {
							color: #FFFFFF;
							font-size: 32rpx;
							font-weight: 800;
							padding-left: 10rpx;
							box-sizing: border-box;
						}
					}

					.right {
						display: flex;

						.text {
							color: #FFFFFF;
							font-size: 24rpx;
							font-weight: 400;
							padding-right: 10rpx;
							box-sizing: border-box;
						}

						image {
							width: 28rpx;
							height: 28rpx;
						}
					}
				}

				.title {
					height: 90rpx;
					line-height: 90rpx;
					color: #FFFFFF;
					font-size: 32rpx;
					font-weight: 800;
					padding-left: 30rpx;
					box-sizing: border-box;
					position: relative;

					&::after {
						content: "";
						width: 8rpx;
						height: 30rpx;
						background: #DDF247;
						position: absolute;
						left: 11rpx;
						top: 50%;
						transform: translateY(-50%);
					}
				}

				.parse_view {
					color: #999999;
					font-size: 26rpx;
				}
			}
		}

		.footer {
			width: 100%;
			height: $footerHeight;
			padding: 0 30rpx;
			box-sizing: border-box;
			background: #111111;
			display: flex;
			justify-content: space-between;
			align-items: center;
			position: fixed;
			left: 0;
			bottom: 0;
			z-index: 2;

			.left {
				color: #DDF247;

				.unit {
					font-size: 40rpx;
				}

				.value {
					font-size: 50rpx;
					font-family: DINPro;
				}
			}

			.btn {
				width: 200rpx;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				color: #111111;
				font-size: 28rpx;
				font-weight: bold;
				border-radius: 20rpx;
				background: #DDF247;

				&.end {
					color: #111111;
					background: #CCCCCC;
				}
			}
		}
	}
</style>